package com.ruoyi.message.mapper;

import java.util.List;
import com.ruoyi.message.domain.IotMessage;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 消息通知Mapper接口
 * 
 * @author wujiale
 * @date 2025-04-26
 */
public interface IotMessageMapper 
{
    //改状态为1
    @Update("update iot_message set read_status = 1 where message_id = #{messageId}")
    public int updateStatus(Long messageId);
    /**
     * 合并两张表并按创建时间降序查询（结果用 IotMessage 接收）
     * @return 合并后的消息列表（按创建时间倒序排列）
     */
    @Select({
            "SELECT ",
            "  b.message_id AS messageId, ",
            "  b.user_id AS userId, ",
            "  b.message_type AS messageType, ",
            "  b.content AS content, ",
            "  b.send_time AS sendTime, ",
            "  b.read_status AS readStatus,",
            "  b.create_time AS createTime,",
            "  b.create_by AS createBy, ",
            "  b.update_by AS updateBy, ",
            "  b.update_time AS updateTime ",
            "FROM iot_broadcast_message b",
            "UNION ALL ",
            "SELECT ",
            "  m.message_id AS messageId, ",
            "  m.user_id AS userId, ",
            "  m.message_type AS messageType, ",
            "  m.content AS content, ",
            "  m.send_time AS sendTime, ",
            "  m.read_status AS readStatus,",
            "  m.create_time AS createTime,",
            "  m.create_by AS createBy, ",
            "  m.update_by AS updateBy, ",
            "  m.update_time AS updateTime ",
            "FROM iot_message m where m.user_id = #{userId} ",
            "ORDER BY createTime DESC"
    })
    public List<IotMessage> selectAllMessageList(IotMessage iotMessage);
    /**
     * 查询消息通知
     * 
     * @param messageId 消息通知主键
     * @return 消息通知
     */
    public IotMessage selectIotMessageByMessageId(Long messageId);

    /**
     * 查询消息通知列表
     * 
     * @param iotMessage 消息通知
     * @return 消息通知集合
     */
    public List<IotMessage> selectIotMessageList(IotMessage iotMessage);

    /**
     * 新增消息通知
     * 
     * @param iotMessage 消息通知
     * @return 结果
     */
    public int insertIotMessage(IotMessage iotMessage);

    /**
     * 修改消息通知
     * 
     * @param iotMessage 消息通知
     * @return 结果
     */
    public int updateIotMessage(IotMessage iotMessage);

    /**
     * 删除消息通知
     * 
     * @param messageId 消息通知主键
     * @return 结果
     */
    public int deleteIotMessageByMessageId(Long messageId);

    /**
     * 批量删除消息通知
     * 
     * @param messageIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteIotMessageByMessageIds(Long[] messageIds);
}
